import java.util.Vector;


public class Process {
	Vector<Function> process;
	String in;
	Vector<State> state;
	int counter;
	
	public Process(String in){ 
		counter = 0;		
		state = new Vector<State>();
		state.add(new State(counter, ""));
		this.in = in;
		process = new Vector<Function>();
		String [] aux = in.split("\\,");
		for(int i = 0; i < aux.length; i++){
			//Testar se ja nao existe ou estado inicial
		process.add(new Function(aux[i], state.get(state.size()-1), this));
		}
	}
	public int getCounter(){
		return counter;
	}
	public State getLastState(){
		return state.get(state.size()-1);
	}
	public void addState(String master){
		state.add(new State(counter+1, master));
		counter++;
	}
	public void addState(State st){
		state.add(st);
		counter++;
	}
	public State getStateByMaster(String master) {
		for(int i = 0; i < state.size(); i++){
			if(state.get(i).getMasterProcess().equals(master)){
				return state.get(i);
			}
		}
		return null;
	}
	public String toString(){
		String s = "";
		for(int i = 0; i < process.size(); i++){
			s = s + process.get(i).toString()+"\n";
		}
		return s;
	}
}
